/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.conference;

import com.nus.constant.ConstantStatus;
import com.nus.dataaccess.dao.author.Author;
import com.nus.dataaccess.dao.base.BaseEntity;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import com.nus.dataaccess.dao.event.Event;
import java.util.ArrayList;

/**
 *
 * @author robin.foe
 */

@SuppressWarnings("serial")
@DynamicUpdate
@DynamicInsert
@Entity
@Table(name="CONFERENCE")
public class Conference extends BaseEntity{

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    public Long getId() {return id;}
    public void setId(Long id) {this.id = id;}
    @Override
    public Serializable getPk() {return this.getId();}

    @Column(name="NAME")
    private String name;
    public String getName() {return name;}
    public void setName(String name) {this.name = name;}

    @Column(name="DESCRIPTION")
    private String description;
    public String getDescription() {return description;}
    public void setDescription(String description) {this.description = description;}

    @Column(name="CONFERENCE_STATUS", length=1, columnDefinition="CHAR(1)")
    private String conferenceStatus = ConstantStatus.CONF_REV_STS_PENDING;
    public String getConferenceStatus() {return conferenceStatus;}
    public void setConferenceStatus(String conferenceStatus) {this.conferenceStatus = conferenceStatus;}
    @Column(name="STARTDATE")
    private String startDate;
    public String getStartDate() {return startDate;}
    public void setStartDate(String startDate) {this.startDate = startDate;}

    @Column(name="ENDDATE")
    private String endDate;
    public String getEndDate() {return endDate;}
    public void setEndDate(String endDate) {this.endDate = endDate;}

    @OneToMany(mappedBy="conference")
    private List<ConferenceAuthor> conferenceAuthors = new ArrayList<ConferenceAuthor>();
    public List<ConferenceAuthor> getConferenceAuthors() {return conferenceAuthors;}
    public void setConferenceAuthors(List<ConferenceAuthor> conferenceAuthors) {this.conferenceAuthors = conferenceAuthors;}

    @OneToMany(mappedBy="conference")
    private List<Event> conferenceEvents;
    public List<Event> getConferenceEvents() {return conferenceEvents;}
    public void setConferenceEvents(List<Event> conferenceEvents) {this.conferenceEvents = conferenceEvents;}

    /******************** UTILITY *****************************/
    public boolean isAuthor(Long userId){
        for(ConferenceAuthor conferenceAuthor : this.getConferenceAuthors()){
            for(Author author : conferenceAuthor.getAuthors()){
                if(author.getUserAccountId().equals(userId))
                    return true;
            }
        }
        
        return false;
    }
    
    
}
